// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.util.list;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import zombie.util.IntCollection;
import zombie.util.hash.DefaultIntHashFunction;
import zombie.util.util.Exceptions;

public class IntArrayList extends AbstractIntList implements Cloneable, Serializable {
    private static final long serialVersionUID = 1L;
    private static final int GROWTH_POLICY_RELATIVE = 0;
    private static final int GROWTH_POLICY_ABSOLUTE = 1;
    private static final int DEFAULT_GROWTH_POLICY = 0;
    public static final double DEFAULT_GROWTH_FACTOR = 1.0;
    public static final int DEFAULT_GROWTH_CHUNK = 10;
    public static final int DEFAULT_CAPACITY = 10;
    private transient int[] data;
    private int size;
    private int growthPolicy;
    private double growthFactor;
    private int growthChunk;

    private IntArrayList(int int0, int int2, double _double, int int1) {
        if (int0 < 0) {
            Exceptions.negativeArgument("capacity", String.valueOf(int0));
        }

        if (_double < 0.0) {
            Exceptions.negativeArgument("growthFactor", String.valueOf(_double));
        }

        if (int1 < 0) {
            Exceptions.negativeArgument("growthChunk", String.valueOf(int1));
        }

        this.data = new int[int0];
        this.size = 0;
        this.growthPolicy = int2;
        this.growthFactor = _double;
        this.growthChunk = int1;
    }

    public IntArrayList() {
        this(10);
    }

    public IntArrayList(IntCollection c) {
        this(c.size());
        this.addAll(c);
    }

    public IntArrayList(int[] capacity) {
        this(capacity.length);
        System.arraycopy(capacity, 0, this.data, 0, capacity.length);
        this.size = capacity.length;
    }

    public IntArrayList(int capacity) {
        this(capacity, 1.0);
    }

    public IntArrayList(int capacity, double _growthFactor) {
        this(capacity, 0, _growthFactor, 10);
    }

    public IntArrayList(int capacity, int _growthChunk) {
        this(capacity, 1, 1.0, _growthChunk);
    }

    private int computeCapacity(int int1) {
        int int0;
        if (this.growthPolicy == 0) {
            int0 = (int)((double)this.data.length * (1.0 + this.growthFactor));
        } else {
            int0 = this.data.length + this.growthChunk;
        }

        if (int0 < int1) {
            int0 = int1;
        }

        return int0;
    }

    public int ensureCapacity(int capacity) {
        if (capacity > this.data.length) {
            int[] _int = new int[capacity = this.computeCapacity(capacity)];
            System.arraycopy(this.data, 0, _int, 0, this.size);
            this.data = _int;
        }

        return capacity;
    }

    public int capacity() {
        return this.data.length;
    }

    @Override
    public void add(int index, int v) {
        if (index < 0 || index > this.size) {
            Exceptions.indexOutOfBounds(index, 0, this.size);
        }

        this.ensureCapacity(this.size + 1);
        int _int = this.size - index;
        if (_int > 0) {
            System.arraycopy(this.data, index, this.data, index + 1, _int);
        }

        this.data[index] = v;
        this.size++;
    }

    @Override
    public int get(int index) {
        if (index < 0 || index >= this.size) {
            Exceptions.indexOutOfBounds(index, 0, this.size - 1);
        }

        return this.data[index];
    }

    @Override
    public int set(int index, int v) {
        if (index < 0 || index >= this.size) {
            Exceptions.indexOutOfBounds(index, 0, this.size - 1);
        }

        int _int = this.data[index];
        this.data[index] = v;
        return _int;
    }

    @Override
    public int removeElementAt(int index) {
        if (index < 0 || index >= this.size) {
            Exceptions.indexOutOfBounds(index, 0, this.size - 1);
        }

        int int0 = this.data[index];
        int int1 = this.size - (index + 1);
        if (int1 > 0) {
            System.arraycopy(this.data, index + 1, this.data, index, int1);
        }

        this.size--;
        return int0;
    }

    @Override
    public void trimToSize() {
        if (this.data.length > this.size) {
            int[] _int = new int[this.size];
            System.arraycopy(this.data, 0, _int, 0, this.size);
            this.data = _int;
        }
    }

    public Object clone() {
        try {
            IntArrayList intArrayList0 = (IntArrayList)super.clone();
            intArrayList0.data = new int[this.data.length];
            System.arraycopy(this.data, 0, intArrayList0.data, 0, this.size);
            return intArrayList0;
        } catch (CloneNotSupportedException cloneNotSupportedException) {
            Exceptions.cloning();
            return null;
        }
    }

    @Override
    public int size() {
        return this.size;
    }

    @Override
    public boolean isEmpty() {
        return this.size == 0;
    }

    @Override
    public void clear() {
        this.size = 0;
    }

    @Override
    public boolean contains(int v) {
        for (int _int = 0; _int < this.size; _int++) {
            if (this.data[_int] == v) {
                return true;
            }
        }

        return false;
    }

    @Override
    public int indexOf(int c) {
        for (int _int = 0; _int < this.size; _int++) {
            if (this.data[_int] == c) {
                return _int;
            }
        }

        return -1;
    }

    @Override
    public int indexOf(int index, int c) {
        if (index < 0 || index > this.size) {
            Exceptions.indexOutOfBounds(index, 0, this.size);
        }

        for (int _int = index; _int < this.size; _int++) {
            if (this.data[_int] == c) {
                return _int;
            }
        }

        return -1;
    }

    @Override
    public int lastIndexOf(int c) {
        for (int _int = this.size - 1; _int >= 0; _int--) {
            if (this.data[_int] == c) {
                return _int;
            }
        }

        return -1;
    }

    @Override
    public boolean remove(int v) {
        int _int = this.indexOf(v);
        if (_int != -1) {
            this.removeElementAt(_int);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int[] toArray() {
        int[] _int = new int[this.size];
        System.arraycopy(this.data, 0, _int, 0, this.size);
        return _int;
    }

    @Override
    public int[] toArray(int[] _int) {
        if (_int == null || _int.length < this.size) {
            _int = new int[this.size];
        }

        System.arraycopy(this.data, 0, _int, 0, this.size);
        return _int;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (!(obj instanceof IntList)) {
            return false;
        } else {
            int _int = 0;
            IntListIterator intListIterator = ((IntList)obj).listIterator();

            while (_int < this.size && intListIterator.hasNext()) {
                if (this.data[_int++] != intListIterator.next()) {
                    return false;
                }
            }

            return _int >= this.size && !intListIterator.hasNext();
        }
    }

    @Override
    public int hashCode() {
        int int0 = 1;

        for (int int1 = 0; int1 < this.size; int1++) {
            int0 = 31 * int0 + DefaultIntHashFunction.INSTANCE.hash(this.data[int1]);
        }

        return int0;
    }

    private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
        objectOutputStream.defaultWriteObject();
        objectOutputStream.writeInt(this.data.length);

        for (int _int = 0; _int < this.size; _int++) {
            objectOutputStream.writeInt(this.data[_int]);
        }
    }

    private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
        objectInputStream.defaultReadObject();
        this.data = new int[objectInputStream.readInt()];

        for (int _int = 0; _int < this.size; _int++) {
            this.data[_int] = objectInputStream.readInt();
        }
    }
}
